package com.bytedance.frameworks.b.a;

import java.util.HashMap;

public final class ComponentsManifest {
    private static HashMap components = new HashMap();

    public static <T> T findComponent(Class<T> clazz) {
        Object v0_1;
        Object v1 = null;
        synchronized (ComponentsManifest.components) {
            if (ComponentsManifest.components == null) {
                v0_1 = v1;
            } else {
                String clazzName = clazz.getName();
                if (ComponentsManifest.components.containsKey(clazzName)) {
                    v0_1 = ComponentsManifest.components.get(clazzName);
                    if (v0_1 != null && ((HashMap) v0_1).size() != 0) {
                        v0_1 = ((HashMap) v0_1).values().iterator().next();
                        return (T) v0_1;
                    } else {
                        return (T) v1;
                    }
                } else {
                    v0_1 = v1;
                }
            }

            return (T) v0_1;
        }
    }

    public static <T> void addComponent(Class<T> clazz, T component) {
        synchronized (ComponentsManifest.components) {
            if (component == null) {
                return;
            } else {
                if (ComponentsManifest.components == null) {
                    ComponentsManifest.components = new HashMap();
                }

                String clazzName = clazz.getName();
                HashMap components2 = (HashMap) ComponentsManifest.components.get(clazzName);
                if (components2 == null) {
                    components2 = new HashMap();
                    ComponentsManifest.components.put(clazzName, components2);
                }

                components2.put(component.getClass().getName(), component);
            }
        }
    }
}

